/*
 *  Created by Max on 2021/3/26.
 *  Print log info in Android Logcat.
 *  To be used in Native C++ project.
 *  Copyright (c) 2021-2024 Max 1020983046@qq.com
 */

#pragma once
//0 导入Android Logcat相关
#include <android/log.h>
#include <unistd.h>
#include <libgen.h>

#define LOG_TAG "ffmpeg_decoder_pure"
//1 可以决定是否在logcat打印日志
#define USE_LOGCAT 1

//2 定义日志打印函数
#if USE_LOGCAT
	#define LogOut(level, FMT, ...)  __android_log_print(level, LOG_TAG, "[%d*%s:%d:%s]:" FMT, \
								gettid(), basename(__FILE__), __LINE__, __FUNCTION__, ## __VA_ARGS__)
	#define LOGV(FMT, ...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "[%d*%s:%d:%s]:" FMT,	\
								gettid(), basename(__FILE__), __LINE__, __FUNCTION__, ## __VA_ARGS__)
	#define LOGD(FMT, ...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "[%d*%s:%d:%s]:" FMT,	\
								gettid(), basename(__FILE__), __LINE__, __FUNCTION__, ## __VA_ARGS__)
	#define LOGI(FMT, ...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, "[%d*%s:%d:%s]:" FMT,	\
								gettid(), basename(__FILE__), __LINE__, __FUNCTION__, ## __VA_ARGS__)
	#define LOGW(FMT, ...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, "[%d*%s:%d:%s]:" FMT,	\
								gettid(), basename(__FILE__), __LINE__, __FUNCTION__, ## __VA_ARGS__)
	#define LOGE(FMT, ...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "[%d*%s:%d:%s]:" FMT,	\
								gettid(), basename(__FILE__), __LINE__, __FUNCTION__, ## __VA_ARGS__)
	#define LOGF(FMT, ...) __android_log_print(ANDROID_LOG_FATAL, LOG_TAG, "[%d*%s:%d:%s]:" FMT,	\
								gettid(), basename(__FILE__), __LINE__, __FUNCTION__, ## __VA_ARGS__)
	#define MARK(FMT, ...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, "[%s:%d:%s]:" FMT,	\
								basename(__FILE__), __LINE__, __FUNCTION__, ## __VA_ARGS__)
#else
	#define LogOut(...)
	#define LOGV(...)
	#define LOGD(...)
	#define LOGI(...)
	#define LOGW(...)
	#define LOGE(...)
	#define LOGF(...)
	#define MARK(...)
#endif

//3 定义函数过程日志打印（进入，返回）
#define ENTER()      		LOGD("begin");
#define ENTER_THIS() 		LOGD("begin  this:%x", this);
#define EXIT()       		LOGD("end");
#define RETURN(code, type) 	{type RESULT = code; LOGD("end (%d)", RESULT); return RESULT; }
#define RET(code)    		{LOGD("end"); return code; }
#define PRE_EXIT()   		{LOGD("end"); }

//4 定义logcat级别
#define LERROR 	ANDROID_LOG_ERROR
#define WARN   	ANDROID_LOG_WARN
#define INFO   	ANDROID_LOG_INFO
#define DEBUG  	ANDROID_LOG_DEBUG



